package com.ruoyi.web.controller.system;

import java.util.List;
import java.util.stream.Collectors;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.com.service.IComUserService;
import com.ruoyi.common.core.domain.entity.ComUser;
import com.ruoyi.system.domain.vo.ComUserVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.ArrayUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.entity.SysDept;
import com.ruoyi.common.core.domain.entity.SysRole;
import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.service.ISysDeptService;
import com.ruoyi.system.service.ISysPostService;
import com.ruoyi.system.service.ISysRoleService;
import com.ruoyi.system.service.ISysUserService;

/**
 * 用户信息
 *
 * @author ruoyi
 */
@RestController
@RequestMapping("/system/user")
@Api(value = "子系统用户管理", tags = {"子系统用户管理"})
public class SysUserController extends BaseController
{
    @Autowired
    private IComUserService comUserService;

    /**
     * 获取用户列表
     */
    @GetMapping("/list")
    @ApiOperation(value = "获取用户列表")
    public TableDataInfo list(ComUserVo comUser)
    {
        startPage();
        Long deptId = SecurityUtils.getLoginUser().getDeptId();
        comUser.setDeptId(deptId);
        List<ComUser> list = comUserService.selectComUserList(comUser);
        return getDataTable(list);
    }


    /**
     * 获取用户详细信息
     */
    @GetMapping(value = "/{userId}")
    @ApiOperation(value = "获取用户详细信息")
    public AjaxResult getInfo(@PathVariable("userId") Long userId)
    {
        Long deptId = SecurityUtils.getLoginUser().getDeptId();
        return success(comUserService.selectComUserByUserIdAndDeptId(userId,deptId));
    }


    /**
     * 修改用户
     */
    @Log(title = "修改用户", businessType = BusinessType.UPDATE)
    @ApiOperation(value = "修改用户")
    @PutMapping
    public AjaxResult edit(@Validated @RequestBody ComUser user)
    {
        user.setUpdateId(getUserId());
        return toAjax(comUserService.updateUser(user));
    }

}
